package com.itHsuSE.demo5;

import java.util.Arrays;

/**
 * @author Hsu琛君珩
 * @version 1.0
 */
public class Test8 {
    public static void main(String[] args) {
        int[] nums={100,100};
        int target=-400;
        findTargetSumWays(nums,target);
    }

    public static int findTargetSumWays(int[] nums, int target) {
        int sum=0;
        for(int num:nums){
            sum+=num;
        }
        //if(target<0)return 0;
        int bagSize=(sum+target)/2;
        if((sum+target)%2!=0)return 0;
        if(bagSize<0)bagSize=-bagSize;
        int[] dp=new int[bagSize+1];
        dp[0]=1;
        for(int i=0;i<nums.length;i++){
            for(int j=bagSize;j>=nums[i];j--){
                dp[j]+=dp[j-nums[i]];
            }
        }
        System.out.println(Arrays.toString(dp));
        return dp[bagSize];
    }
}
